package edu.nf.redismqes.service.factory;

import edu.nf.redismqes.service.handler.NewHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import jakarta.annotation.PostConstruct;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ Author bin
 * @ Create  2025/10/22 上午9:32
 * 策略工厂
 **/
@Component
public class NewHandlerFactory {
    @Autowired
    private  List<NewHandler> handlers;
    @Autowired
    private final Map<String, NewHandler> handlerMap = new HashMap<>();

    @PostConstruct
    public void init() {
        handlers.forEach(h -> handlerMap.put(h.getAction(), h));
    }

    public NewHandler getHandler(String action) {
        return handlerMap.get(action);
    }
}
